fixed bug with buffer copy