properly selecting which rows to swap