Remove the duplicated code.

This completes the refactoring.