Finished separating the code.  Found a bug where multiple threads were being created (there's a single lock, so it wasn't a critical bug, but it could chew up scheduler fairness).
TODO: lots of debugging.  Especially of states.