A good NOTE comment explaining this algorithm would be helpful for posterity.