Fix typehint
Add tests for exceptions
Misc fixes