refactoring into a library and a command line interface