fixing buffer write