fixed bug in read_bytes(), the call to read() should be inside the loop