Added validation, completing chapter 3 in the book