add segment function