fix on writing bytes from a buffer