faster C implementation