Moved event handling from the main loop to inputwrapper