Cleaned up C++ code. Added example/test patch.