removed unused variables
fixed the NaN bug