Fixed calculateFitness function