Export segments function, removing duplication.