making the conversion code more scalalike