Fixed median method and added tests