c code and minor tests