Replaced some chars with 8-bit ints. Chose size-specific functions for writing.