revived standalone c version. about to merge with the master branch