Fix bug in generateBest