Attempt to write a purely C implementation