Fixed NaN issue in JS