Added checking for empty query result