žClarity induces correctness
lBefore
–Unclear
–Inconsistent
–Buggy
lAfter
–Clear
–Consistent
–Correct
The code you will see very shortly may look a little strange to you.  That’s always the case with someone else’s work, but this code is somewhat difficult to understand.  In some cases something was done once one way and once a different way so that it problems aren’t obvious.  Indeed, there seems to be a small bug somewhere in each version of the function.  You may be able to find it right away, but I encourage you to clean up the code first so that the problem is obvious.  Clean it up either way.