Refactored a bunch.