Tried to fix error handling