Optimized the code