adding checks to optimizer