updated functions.r