Pure C version