fixed the NaN problems