added example codes from O'Reilly website