Finalized (commented C code)