rewrote C code to shorten communication