Converted some Java to Scala.