boilerplate code to handle mouse events