updated code for closing input stream.