Break up functions to prepare for testing

We want to break up the code into small testable units so that we can verify things work as we expect (and so that we have better modularity of code for later reuse [and better organization/clarity]).

This takes us one more step into that direction.