Numerous bug fixes to the STM code, mostly from a debugging session with Tim Harris. The test that flushed out all the bugs will shortly be added to the test suite.