adding better event handling