Remove some code duplication in conversion.