Fixes and optimizes mouse events