Optimization some codes