Minor refactorings to the Java and Scala code