Various fixes and cleanups
Refactored error reporting with an exception