refactored search and works properly now