C implementation!