added event handling to support multiple windows