Added condition and NilClass check