When social influence promotes the wisdom of crowds