First median function added