Fix type casting bug