fix "undefined method [] for nil:NilClass"