modfified on buffer free func