solved in Scala!