More optimizations, smarter mouse event handling