Improved query class.