Handle nested functions properly