Start refactoring into a library + CLI