Fix scope error
Fixes part of #138
Added test for scope issue #138
Merge pull request #149 from DickvdBrink/scope-error

Fix scope error