(maint) Reoder code to increase clarity

There were a lot of unless cases that made it hard for me to track down
the path of what was actually accepted. This inverts the branches so
that the if statements lay out what is required for the good case and
the else clauses express the various failures.

In addition there were a few error scenarios where reordering was
possible and reduced the amount of work that needed to be done before
the error was detected.