Refactoring to allow some stuff to be more easily reusable.