slight refactor of rewrite_v1