Query translation speed improvements and code cleanup.