Refactoring cardinalitymismatch exception