Added optimized script for part 3