Rewrite to C++. Initial commit