Fixed InputStream read() bug - returning incorrect value