first attempt at swapping code