Added unit tests; minor bug fixes to lib