Added an event handling class and created the main loop.