slightly more modular lib, fixing up tests...