simply code for c implementation