rewrote exercise 1-23 with another approach