Rewrite internal ast and type interface