Updated main loop to run correctly.  Fixed code format using uncrustify.