simplify algorithm
simplify algorithm