fixed writeBuffer bug