refactor threading model