fix scoping bug