Refactor using threading macro