fixing undefined method []' for nil:NilClass