A bigger refactor

cc @nathan7