refactoring. tidier use of jquery