Fix scopes of variables