refactored publish method for clarity