Fix for NoMethodError: undefined method `text' for nil:NilClass