Add some input sanitation and validation.

Still more of this to be done.