rewrite publish_events definition