Move Application Logic Into 'application' Stack Script
It is a good idea to use the built-in messages that the framework sends when your application initializes, opens and shuts down.
The 'application' Stack Script
If you edit the script of the application stack you will see all of the messages that the framework sends. You can find descriptions of the messages in the API docs.
For example, you should put any code that is application specific (registring libraries, fonts, database drivers, etc.) into the glxapp_initializeApplication message. You open your program window in the glxapp_openApplication message.