rewrite mostly complete