some changes in optimization code