Cleaned up naming and avoided some pitfalls in JSON output. Highly unstable commit.