Refactor libraries to better separate concerns.  Unit tests added.