Why do you do things like:
assert(doSomethingThatChangesState() == 0);
throughout your code? I thought the point of assert was for debugging purposes and you should never change program state inside the assertion.