Add initial multithreading. Works, but needs refactoring.