Refactors code, flips preventDefault() function call and search() function call