finish slgorithm