Correction for read/write buffer greater than 512 byte

Thanks to William Greiman for pointing this bug