added line to check if input stream is ready to be read.