Code optimization for speedup