fixing error handling