Put all input checking in a new function.

Increases encapsulation.