Refactoring

Replaced type comparison with typecast to iterable