Modified views and insertJSON to add exception handling