Converted all Java code to Scala