Filter out stale search results, plus some minor refactoring.