More steps towards implementing search. Code has to be heavily refactored.