bring over some changes/fixes from O'Reilly book