Refactored code and added a nested json script