Fix to handle empty $query results.