more preparation for search
port commit 9e7d0df3e61fda88a2788dd410df4202bb5867f8 over from master