corrected code segments, fixed last example