Refactor straight-line code into a library.