no more offset validation (buf.write...)
code compacted