Refactored archive handling. Fixes #413