Converted Mod to Scala