Refactored SearchEntities and split into smaller methods

This refactoring patch does not contain any functional changes on
purpose. I split other [WIP] changes (that contain functional
changes) and would like to merge this pure refactoring patch first,
please.

Change-Id: I988b39aec281519f48ac4f262d0bd79117b7705d
Merge "Refactored SearchEntities and split into smaller methods"