fixed implementation for c