Added search functionality
refactored the code