Re-implementation in C++ and separate threads to