Refactor some search stuff

ideally, you would never create the keys in the first place, but I'm okay with this because it's easy to read