trying to track down bug in C code