added error codes and json responses'