code from the talk, with comments