some refactoring, put search in separate file