Factoring out some common behaviour to avoid code duplication.