fix error handling by seperately handling errors