unfortunatly i am not good enough to convert the C code