- simplified and improved copyfile function