ga is the wrong approach for that. In ga, you never modify the population in the objective function. Instead, you generate a fitness value for the population as-is. Then the population along with all of the fitness values are passed to the crossover or mutation functions, which can generate whatever modified values desired.
To phrase this a different way, take that detection and modification code out of the fitness function and put it in the crossover or mutation function.