Refactored event handling, not sure if this works out