Refactoring.

Return lists instead of strings from lower-level routines, and remove some
unnecessary local variable declarations and assignments.
Refactoring.

Name helper functions more clearly and give them a purpose rather than being
simply helpers for the main code.