Correct Algorithm