Fixes switch statement
Adds checking of returned JSON object to determine success or errors