optimize phases