made a swapping function.