Cleaned up code for search and facet