finish algorithm fix