Add nil check for response.
The logic of nil check might be wrong. fixed it.