Finished c version