A little cleanup.

Shorten long lines, extract a function, and add comments.
Merge pull request #1540 from braddunbar/template

A little cleanup.
Conform with project style.
Merge pull request #1541 from braddunbar/else-if-style

Conform with project style.