I simply gave up understanding the whole thing, and restored the balance in the universe by rewriting it in Perl.
But it's such a painful language to look at.