replace Fig 16.3-5 to selectable code