fix null handling for query