Converting this project from Javascript to C++