refactoring mousleave event in js