Fixed stack overflow when factoring some expressions
Implemented Partition