initial port of partition function (needs more work)