Fixed nested scopes and optimizing (FOR REAL)