Could we merge this in to fix the various bugs with automatic regeneration and then refactor later to remove the redundancy? There's already a lot of redundancy here already.