logic for swapping updated