Added optimized Part 2 code.