fixed a casting bug in optimizer