refactor: factor out code to get worker function