Fixed a few minor errors. Separated the json generation code.

Woo hop, it works