A few bugfixes. I don't believe it, it actually works!

(I'm sure I'll be able to break it if I try hard enough, so now to write
proper tests for the STM system...)