Separated some code and put it in global.R