Refined nextHighestNumber function by combining conditionals.