added togglePublish function