refactored json parsing; style fixes;