Updated code for part 2