Adding the finished part 1. Use the code in Part1 as it works for all cases that we have to support