add proper HTTP response code check for credential verification
free allocated resources earlier