Refactoring out a lot of uneeded duplication.