c functions seems to be correct now