Refactored code to use jQuery