Cleaning up mouse event code & fixing a bug (reported by monoped, thanks!)