update median function