Fixed a critical error in handling the query in the diversity functions.