Converted C++ source to C

Reason: C++ features were not being used, and C is more managable and quicker to compile.
Corrected warnings, and made minor improvements