Minor edits: create functions for long code blocks

Leverage multiple assignment.
Better use of format().
Tighten up if / else assignments.
Merge pull request #1 from cclauss/patch-1

Minor edits: create functions for long code blocks