optimize segment joining