Refactor searching codebase

I've refactored the code relating to search to be more concise and clear. #bugshare