Add comments and check for status code of response returned by authenticate