Refactor so part of the code looks more like a library, and can easily be made so.