Refactor some search stuff

this is where I get a bit confused