fixing restart algorithm.