Cleaned up the C code and comments