necessary changes in optimize