More fixes to error handling and stacktraces