Finish algorithm. unverified.