Simpler and more robust now that contexts are not shared between threads. Patch attached.