Refactor publish event method