refactor to make more DRY
test seems to run on python 3.3