Configuration, refactor, and tests

/cc @nbryan

Just for review; I'm gonna merge it now.