working core/algorithm.cpp version