refactor code with jQuery