Fixing error handling