Added logic for when query returns 0 rows