needed to check buffer length when writing