fixed various issues with scope