Minor edits: create functions for long code blocks

Leverage multiple assignment.
Better use of format().
Tighten up if / else assignments.