fix NoMethodError: undefined method similar for nil:NilClass