improved simplify, fixed reversegraph, testing for loops