finish refactoring the old code for algo1.