refactored ajax search function