Refactored search javascript.