Adding validation and error checking

Section 5.1.1 of tutorial