fixed error output, use of buffer and add buffer to output