Scala: moved helper functions to inner scope.