code for global optimization, missing g and depth