Fix some error handling and tracing issues
Fix #1315
Fix #1314
Fix #1318