Refactored and improved search engine