implemented nextgen algorithm