Some refactoring around mouse and touch events.