refactoring jquery code