Add guard for variables being cleared during a function call.
Add test for clearing