Rewrote overall event handling