Refactors code in functions by incorporating jQuery