optimized the code structure