moved code into library