Rewiring in partial environments, part 3

Also a bit of test cleanup, there are already quite a few tests :)