Fixed mistake in threshold algorithm;