rewrite hostorybuffferadd function, histotyreadprevious function still broken