Add error checks TODO done

Added necessary checks for possible error codes return.