Implement sample codes from p247 to p249