remove dead code and reorganize program templates