Updated to use median