refactored JSON parsing code, added documentation comments