Refactor mouse code.