Added a little bit of event handling