Added medioid function