Changed Implementation of search, refactored code