fix bug with optimization