Correct algorithm which was false