Base (non-machine learning) code pulled out from jml