reduce code duplication
Merge pull request #2 from marmbrus/pr/2246

reduce code duplication