A Stochastic Model of Optimal Debt Management and Bankruptcy