Adding code for part 4 of the series