finish last algorythm