more progress on AI rewrite