Large refactoring. Got #search to return valid json