Integrated newest algorithm version and its tests from master.