Moved code to callback of $.getJSON call