Modularize R code a little bit.