Rearranged library to allow exposure of private members for testing. Also implemented some unit tests.