thanks. can you add your explanation in comments? 

another question: why does this function take three nodes?