Revert "More duplicate code cleanup"

This reverts commit d4333c7ff9429061be2d6be3bbf50b5c20bb0e36.
More duplicate code cleanup