Fix casting bug