Improve program startup code.

Avoid unnecessary classes creation.
Simplify main() logic.
Add Application class and put application initialization code to it.
Place some code into separate functions.