initial work on rewrite