add json output
reformat code to be closer to PEP 8