refactoring for library use