Fixed issues with error handling (part 1)