Refactor publish code.