Refactoring and search improvements