Handle the odd and even cases correctly, though the output doesn't look right.
Implementing the pseudocode from the paper.