Started refactoring in Scala