Fix possible class cast exception