Refactor some code
Support JSON formatting