More work on rewrite