Fix bug in swapping