Refactor search_or_error() #18