wip: rebasing @tknopp's threading branch