C version, very lame