Remove some code duplication.