Added NaN testing in fitness functions