Improved Query class handling