Fixing scoping bug