Fixed a bug and cleaned up C code.