added optimize without infinities