Started re-write in C.