comments added to Part 2, Part 3-4: code finished