updated the way it handles errors