Implement threads

Passes all 27 tests.