Clean up and add documentation to cost2thresh.