converting code to cpp, due to a need to be more efficient