Scala application, uses recursion and functional programming