adjusted: run in a function and in R Studio