remake of segall with some changes