fixed bugs related to scopes