fixes threshold algorithm