added condition for when new number is median