moved swapPoints function