Various small refactors for search code