simplified copy_file code