smal change to algorithm