implemented a version in C