Reworked error handling.