Add initial C++ port of main loop.