fixed casting bug