Add empty checks for query clauses, change output formatting for testing.