Could also have swapped nodes to assign instead of swapping after assigning, but this way it's easier to see whats going on.