refactor code from worker to dialogue manager