here is the new median function