modified ex18.rb