Re #7362. Added validateInputs to the top.

Also re-arranged a bunch of other code. Part of the "clean-up"
that Wenduo had mentioned.
Re #7362. Finished making some parameters optional.