Revert "More multithreading code"

This reverts commit 85942bc8c592bc7e2a4cb72213c4196bf9cd798d.
Revert "Revert "More multithreading code""

This reverts commit 11b02aaad4732c4b437a7138d7158c6b563c339e.
Revert "More multithreading code"

This reverts commit 85942bc8c592bc7e2a4cb72213c4196bf9cd798d.