Remove several bugs in error management.