The program stops when a new page opens

As @ABG already mentioned, you do not switch screens correctly... this would be the first thing to correct...

See also tip 1 here

Taifun