Exercise 3.5.2. parts 1 - 3, argument validation added