fix error handling