Refactored search.js