fix bug in c code implementation