refactoring the genetic algorithm