Fixes for threading bugs

Both had the practical symptom of some messages being threaded to one of their grandparent.  Sorry, I didn't manage to come up with unit tests for every case.