Decomposed main routine into several more manageable functions

 Committer: Jordan McCarthy <mccarthy@opentechinstitute.org>