Refactor Terminal Connection <-> Shell to rely on task identifiers.

Also reset terminal settings upon completing a task.