Reorganized code to clean up some boilerplate.
Merge pull request #2 from bsummer4/cleanup

Reorganized code to clean up some boilerplate.