Fix context problems with nested helper functions