Optimized the code structure