Implemented C version