Optimized code implementation and reorganized code structure