Modification to partition algrorithm