Better error handling and an example class for api