code as of end of part 1 post