add AppMain class
moved main app loop from main() to AppMain class