further attempt to remove code duplication
Merge pull request #49 from theckman/more_refactor

further attempt to remove code duplication