Reduce a bunch of code duplication.