added inputstream error detection