refactor code, output to json files