added C implementation