Clean up query extensions and fix scope issues.