Clean up mouse event handling function
Code cleaned and initial release