Preserve file permissions on copy.
Fixed scoping issue.