Fixed bug on opt algorithm.