Added unit tests for the api controller.  Minor refactoring.