Fixed bugs in buffer/byte reads/writes