refactoring into useful library