basic simplifying algorithm