fixing the NaN issue (work in progress)