seems to calculate segments correctly