replace old code with optimized code