Clean external references and unused sections in template