add write buffer size check