Query engine: Minor fixes for count query