fixing mistake with variable re-assignments