Fix class cast exception