modified code to make jquery safe