optimized code. utilized merge command