refactored mouse code