JSON fixes/refactoring