Several improvements on error handling.