a bit of refactoring + safe handling of empty result sets
new search functionality. TODO: refactor tests, bloody hell