fix copy function