more elegant map swapping code.