added segment comparison function