reworked error handling