refactoring partitioning code, and implementing tree partitioning