Refactor input validation.
Merge pull request #3443 from amueller/input_validation_refactoring

[MRG] Input validation refactoring