ENH: Bug fixes in threshold determination.