switched some ordering in the swap function.