refactor archive logic