Refactor into a library.