Refactor code for archetype generator