generalized mvg function