fixed scoping bug