C version works