Extract function to create prefix search result.

...and some other small changes based on review feedback