mkPartition function improved