publish function mostly written