Added buffer copy function