refactor get median