further work on rewrite; wip