functions - fix scope of nested function calls

Fixes #2