code update as per Robert Lafore's book