Improved mouse event handling