working version - end of part 1