rewrite of the swapping thing