simplify algorithm