Improved query test