fix Caught NoMethodError: undefined method `[]' for nil:NilClass