Fix bug in query_categories func.