Fix the NoMethodError: undefined method [] for nil:NilClass error.