Move the getJSON callback in a separate function and add an error handler