move these functions into library