refactor into library