Refactor some mouse listener code for meaning