Reduce code duplication for getExtension.