minor refactoring
fixed bug in recursive partitioning fn