modified the lazy alg