Fixed JSON formating, refactored code