experimental refactoring of mouse event-handling code