Added a Scala implementation