Get rid of duplicate code revealed by Clone Hunter.
Merge changes from RP.