Revert "Revert "Use threads for parallelization""

This reverts commit 2735221fb56baf2bbcddc1b97a4ccdb3219e92b2.