Fix panic due to a unexpected response, Cleanup code