finish the gray alg