Here’s a valuation model which includes financial distress and agency costs.
X represents either Tc in the MM model or the more complex Miller term.
Conclusion: Optimal leverage involves a tradeoff between the tax benefits of debt financing and the costs associated with financial distress and agency.