code optimization of FRED scripts