Fix: Added check if res obj exists

res obj is sometimes undefined