Large refactoring surrounding the library code. Thankful I have a useable set of tests - it made refactoring a doddle.