Update for better event handling

Event handling plus unit test