Implementing a genetic algorithm