edited alg for disp