CHANGED:applied the swap function