Refactor publish task.