moved internal functions to utiltiies.R