Major update to the archive code

- Use map destructuring to make the expected arguments more clear
- add new function to clean up temp dirs
- Add more doc strings
- make private defs private