Fixed to handle error carefully