simplifying algorithm