Remove unnecessary copying or replace it with moves in a bunch of places.

NFC.