add null handling to query method