added a median function