remove code duplication
Merge pull request #1 from pyeremenko/v3

Remove code duplication