Fix threshold bug