Big refactor of the client library as well as added unit tests.