Moral Hazard and the Optimality of Debt