more refactoring of rmarkdown functions