Query engine fixes