Bugfix: bad index when copying from input to output.