Refactoring api spec.  Added some more tests and did a lot of reorganizing