break the publish method into its own named function
fix global handling