Refactoring / cleanup. No functional change.

Cleaning up code a bit so I can understand it.
Broken app up into explicit modules