introduce Thresholds class, fix unit tests and some other changes to address Joachim"s comments