fixed a variable swap issue