Refactor some stuff to be less terrible.