Refactor run.py and output to json