You should not need prevRef here. It is ok that the prev is null on call to getCost(). This is also the case on first path polygon, only the curr and next are valid.