bug in threshold calculation