fix index ordering in c version