Add scaffolding for rewrite-package command

Also added some small refactoring, but not much.

[#71156874]