Implemented simplify and sped up a little