refactoring for jquery