Added Scala implementation