Domino algorithm, fix problem with swaps