Improve handling of various errors. Add more docs. Add support for subtypes.