Began to move the more portable bits of the code into a library.