Sped up the algorithm of checking mouse enter and leave events.