Query ordering optimization and minor timeout edit