Modularized the code a bit to prep for unit tests

Will make writing tests hopefully a bit easier.  Plus this is probably
just better in general.