Refactored publishing code.