moved mouse event handling into it's own function 'mouseEventHandler'