Added a check for empty query results.