improved scope handling (recursion should work now)