Completed procedure to partition tables