Refactored ajax/JSON calls to single function