redoing algorithm