Remove duplication

This change removes some duplication from the code to improve
CodeClimate metrics.

[#62915462]
Merge 62915462-code-climate to master

[#62915462]