Adding validation

added validation, unit tests and the like.
(end ch7)