Converted fully over to C, with tests and everything.