Fixed bugs with the optimize option