added the older c-code version