Improved the event handling and the viewport