Added some event handlers
this could work. I'll test it later.