added source code from  book