Refactor some search stuff

see above