add test for handleEvent
refactor