in reply to Pop quiz: find the bug

My suspicion is...
If you get a credit on the account, such that either $tcount, $tcash, or one of the others reach zero, you won't trigger the last, and will fall through to an inadvertant (and incorrect) change to $tcredit.
and the rewritten code doesn't suffer the same fate because
it doesn't have the possibility of falling through into a $tcredit update.
.

That's white type above. Select it to see it.