fix test cases
DRY
#300 fix and test cases