Moved code into library