rewrite driver in c
fix trivial compile errors