updated code to fix NaN