Refactored Code to use jquery