fix error in error handling
shorten and simplify