Cleanup nested functions