Bug fix of optimize