refactored all pieces. edges cases are covered. testing partition may be improved later