Updated threshold algorithm