Cleanup + removed some unnecessary copying + fixed premature move.