Fixed errors with scope. Test problem with nested scope now working.