Fix a bug to avoid duplicate solutions