Add back some missing code, remove duplicate lines.