Refactor C++ Code

And fix a CMake typo