used median insead of mean
added median function