Simplifying the API code

Error message with reason.
Polishin

Small changes to the type specs