fix middle scopes, and partial variables fix