added null checks for query datastore queries