Fix potential class cast exception