Refactored JSON parsing with functional methods, applied some code separation.