bug fix for case when buffer is inserted at the end of file