Error Handling, refactoring and API documentation

Added a lot of error handling. Refactored model and API scaffolding
into separate files. Fleshed out the API documentation and prettified
it.