Added Application class, main loop and event handling