added implementation in c