code from the book(and some other books i'm re-reading ATM)