refactoring and adding to advanced search