Refactor file copying
Refactor copying directories
Refactor use of caching and storage functions