Refactor copying and archiving functions