Scala port finished for functional code