fix error handling correctly