Cleaned up middle a bit.

The only really tricky change is that a long chain of ifs, and elses
was turned into a single if, and a match in astencode.rs. Some methods
can only be called in certain cases, and so have to come after the if.