Added proper null handling for queries that return one row