Fix for class cast exception