Significant refactoring for use of the REST API.