fix important bug in optimization