Added a bunch of refinements to the rest-api and some unit tests.