Ported to Scala