Rewrote simplification code