minirefactoring to more Scala-Style, without optimizing -> very slow