add comments; drop dead code; reorganize templates order