Updated core algorithm for quickly convert to C++