Refactor test/refactor.py

for #153