Scripts and R functions (under construction)