factor out the conversion into its own method.

That way other places in the code just need to call the
conversion method instead of doing the conversion itself.