Refactor into a library