scenario code optimization