Major rework to use commons-math.