refactored to remove duplicate code
Merge pull request #102 from jackalope/refactoring

refactored to remove duplicate code