updated segment logic