To avoid messy code, separate all validation of individual parameters into their own functions (and possibly validation class).