Updated partitioning logic