implemented swapping