moved event handling to its own class