Turned some functions into library functions