implemented the necessary event handling