added FPS counting, better event handling and refactored