Eliminate a bunch of code duplication.