optimized the code