Working version before refactor
Refactoring in line with ml4j-core