Initial refactor commit.

Working on decoupling a lot of the things I messed up the first time around.