Refactor search and location update code.