Added some check for errors