Move disconnect command handling to a common place