Fix for a bad class cast exception