Further debugging the head-corner algorithm. Almost working.