Fix writeBytes length

Credit to wilsynet