adding general function for partitioning